﻿#include<stdio.h>
int main()
{
	int i, j, a[2][13] = { {0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
	int year1 = 1923;
	int year, month;
	int sum = 0,B,R=1,K=0;
	printf("输入想要查询的年份和月份\n");
	scanf_s("%d %d", &year, &month);
	printf("%d年%d月\n",year,month);
	printf("一  二  三  四  五  六  日\n");
	for (i = year1; i <year; i++) 
	{
		if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))sum += 366;
		else sum += 365;
	}
	if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))B = 1;
	else B = 0;
	for (i = 1; i < month; i++)
	{
		sum += a[B][i];
	}
	if (sum % 7 != 0)
	{
		K += sum % 7;
	}
	for (i = 1; i <= 7; i++)
	{
		for (j = 1; j <= 7; j++)
		{
			if (i == 1 && j <= K)printf("  ");
			else printf("%-2d", R++);
			if (R == (a[B][month])+1)break;
			printf("  ");
		}
		if (R == (a[B][month])+1)break;
		printf("\n");
	}
	return 0;
}
